<?php $this->jQuery()->enable()?>
<?php $this->JQuery()->javascriptCaptureStart()?>
jQuery(function() {
	$j('#container').attr('class', 'profile company');    
	
	if($j('.act_info').css('display')!='hidden' && $j('.act_ads').css('display')!='hidden' && $j('.act_photo').css('display')!='hidden')
	{
		$j('#container').removeClass('ads');
		$j('#container').removeClass('photo');
		$j('#container').addClass('info');
		$j('.act_photo').hide();
		$j('.act_photo1').hide();
		$j('.act_ads').hide();
		$j('.act_ads1').hide();
		$j('.act_info').show();
		$j('.act_info1').show();
		$j('.act_info2').show();
		$j('.act_info3').show();
	}
	
	$j('.a1').click(function(){
		$j('#container').removeClass('ads');
		$j('#container').removeClass('photo');
		$j('#container').addClass('info');
		$j('.act_photo').hide();
		$j('.act_photo1').hide();
		$j('.act_ads').hide();
		$j('.act_ads1').hide();
		$j('.act_info').show();
		$j('.act_info1').show();
		$j('.act_info2').show();
		$j('.act_info3').show();	
	});
	
	$j('.act_info0').click(function(){
		$j('#container').removeClass('ads');
		$j('#container').addClass('photo');
		$j('#container').removeClass('info');
		$j('.act_photo').show();
		$j('.act_photo1').show();
		$j('.act_ads').hide();
		$j('.act_ads1').hide();
		$j('.act_info').hide();
		$j('.act_info1').hide();
		$j('.act_info2').hide();
		$j('.act_info3').hide();	
	});
	
	$j('.a2').click(function(){
		$j('#container').removeClass('ads');
		$j('#container').addClass('photo');
		$j('#container').removeClass('info');
		$j('.act_photo').show();
		$j('.act_photo1').show();
		$j('.act_ads').hide();
		$j('.act_ads1').hide();
		$j('.act_info').hide();
		$j('.act_info1').hide();
		$j('.act_info2').hide();
		$j('.act_info3').hide();	
	});
	
	$j('.a3').click(function(){
		$j('#container').addClass('ads');
		$j('#container').removeClass('photo');
		$j('#container').removeClass('info');
		$j('.act_photo').hide();
		$j('.act_photo1').hide();
		$j('.act_ads').show();
		$j('.act_ads1').show();
		$j('.act_info').hide();
		$j('.act_info1').hide();
		$j('.act_info2').hide();
		$j('.act_info3').hide();	
	});
	
	<?php echo (!empty($_GET['sort']) || !empty($_GET['page']))?'$j(".a3").click();':''; ?>
	
	$j('.photo_thumb').mouseover(function() {
        $j('#big_photo_cont').html('<img src="' + $j(this).attr('rel') +'" class="big_photo">');
    });

	
});

<?php $this->JQuery()->javascriptCaptureEnd()?>
<section class="profile">
	<div class="intro">
	    <h1><?php echo $this->company->username?></h1>
   		<p><?php echo $this->t('<em>__1__</em> Views', null, $this->company->getNoViews())?></p>

    	<p class="active_since"><?php echo $this->t('Active Since <em>__1__</em>', null, date(MEDIUM_DATE_FORMAT, $this->company->created_at->sec))?></p>

	</div>
	<div class="info">
		
		<!--INFO-->
		<div class="action act_info">
			<span class="selected"><?php echo $this->t('Info')?></span>
			<a class="a2"><?php echo $this->t('Photos')?></a>
			<a class="a3"><?php echo $this->t('Ads')?></a>
		</div>
		<div class="gallery act_info1">
			<a class="act_info0">
				<figure>
					<span>
					<?php if(!empty($this->company->image) && file_exists("../public/images/photo/original/".$this->company->image)):?>
	                	<img src="<?php echo $this->thumbnail()->scale($this->company->image);?>" alt="<?php echo $this->t('__1__ - photo __2__', null, $this->company->username, 1)?>" id="main_photo1">
	                <?php else:?>
	                    <img src="<?php echo $this->thumbnail()->scale('', 298, 298);?>" alt="<?php echo $this->t('__1__ - photo __2__', null, $this->company->username, 1)?>" id="main_photo">
	                        <?php endif;?>
	                    </span>
				</figure>
				<p style="color:#2070A0;"><?php echo $this->t('View Photos')?> &raquo;</p>
			</a>
		</div>
		<div class="detail general act_info2">
		<h2><?php echo $this->t('Company Information')?></h2>
        <?php if (!empty($this->company->mailing_address)) { ?>
        <dl class="address desc">
          <dt><?php echo $this->t('Address')?></dt>
          <dd><?php echo $this->company->mailing_address?></dd>
        </dl>        
        <?php } ?>
        <?php if (!empty($this->company->phone)) { ?>
        <dl class="desc">
          <dt><?php echo $this->t('Company Phone')?></dt>
          <dd><a href="tel:<?php echo $this->company->phone?>"><?php echo $this->company->phone?></a></dd>
        </dl>
        <?php } ?>
        <?php if (!empty($this->company->fax)) { ?>
        <dl class="desc">
          <dt><?php echo $this->t('Fax Number')?></dt>
          <dd><?php echo $this->company->fax?></dd>
        </dl>
        <?php } ?>
        <dl class="desc">
          <dt><?php echo $this->t('Business Category')?></dt>
          <dd><?php 
              $cat = Model_Category::one(array('_id' => new MongoId($this->company->business_category)));
              $id_parent = $cat->path[1];
              $parent = Model_Category::one(array('_id' => new MongoId($id_parent)));
              echo '<a href="'.$parent->url().'">'.$parent->name.'</a> > <a href="'.$cat->url().'">'.$cat->name.'</a>';
          ?></dd>
        </dl>
        <?php if (!empty($this->company->location)) { ?>
        <dl class="desc">
          <dt><?php echo $this->t('Location')?></dt>
          <dd><?php
              $id_parent = $this->company->location->path[0];
              $parent = Model_Location::one(array('_id' => new MongoId($id_parent)));
              echo $parent->name.'  '.$this->company->location->name;
          ?></dd>
        </dl>
        <?php }?>
        <?php if (!empty($this->company->number_employees)) { ?>
        <dl class="desc">
          <dt><?php echo $this->t('No. of Employees')?></dt>
          <dd><?php echo $this->company->number_employees?></dd>
        </dl>        
        <?php } ?>
        <?php if (!empty($this->company->website)) { ?>
        <dl class="desc">
          <dt><?php echo $this->t('Website')?></dt>
          <dd><a href="http://<?php echo $this->company->website?>"><?php echo $this->company->website?></a></dd>
        </dl>
        <?php }?>
        <?php if (!empty($this->company->facebook_twitter)) { ?>
        <dl class="facebook desc">
          <dt><?php echo $this->t('Facebook/Twitter')?></dt>
          <dd><a href="http://<?php echo $this->company->facebook_twitter?>"><?php echo $this->company->facebook_twitter?></a></dd>
        </dl>
        <?php } ?>
        <?php if (!empty($this->company->backlink)) { ?>
        <dl class="email desc">
          <dt><?php echo $this->t('Backlink')?></dt>
          <dd><a href="<?php echo $this->company->backlink?>"><?php echo $this->company->backlink?></a></dd>
        </dl>        
        <?php } ?>
		</div>
		
		<?php if (!empty($this->company->about)) { ?>
	      <div class="detail description act_info3">
	        <h2><?php echo $this->t('Description')?></h2>
	        <p><?php echo $this->company->about?></p>
	      </div>
	      <?php } ?>
		
		<!--PHOTO-->
        <div class="action act_photo">
            <a class="a1"><?php echo $this->t('Info')?></a>
            <span class="selected"><?php echo $this->t('Photos')?></span>
            <a class="a3"><?php echo $this->t('Ads')?></a>
        </div>
        <div class="gallery act_photo1">
        <figure>
            <span id="big_photo_cont">
                    <?php if(!empty($this->company->photos)):?>
            <img src="<?php echo $this->thumbnail()->scale($this->company->photos[0]);?>" alt="<?php echo $this->t('__1__ - photo __2__', null, $this->company->username, 1)?>" id="big_photo">
    <?php else:?>
        <img src="<?php echo $this->thumbnail()->scale('', 298, 298);?>" alt="<?php echo $this->t('__1__ - photo __2__', null, $this->company->username, 1)?>" id="big_photo">
            <?php endif;?>
            </span>
        </figure>
        <!--p>
                <a><span>
                        <img src="<?php echo $this->thumbnail()->resizeAndCrop($this->company->image, 45, 45);?>" class="thumb" alt="<?php echo $this->t('__1__ - photo', null, $this->company->image)?>">
                                </span></a>

        </p-->
		<?php if(!empty($this->company->photos)){?>
		<p>
		<?php foreach($this->company->photos as $photo):?>

                <a><span>
                        <img src="<?php echo $this->thumbnail()->resizeAndCrop($photo, 45, 45);?>" class="photo_thumb" alt="<?php echo $this->t('__1__ - photo', null, $photo)?>" rel="<?php echo $this->thumbnail()->scale($photo);?>">
                                </span></a>


        <?php endforeach;?>
		</p>
		<?php }?>
        </div>

		
		<!--ADS-->
		<div class="action act_ads">
			<a class="a1"><?php echo $this->t('Info')?></a>
			<a class="a2"><?php echo $this->t('Photos')?></a>
			<span class="selected"><?php echo $this->t('Ads')?></span>
		</div>
		<section class="serp act_ads1">
<?php if($this->listing_number>0):?>
	    <h2>
			<span>
			<!--<?php echo (($this->page-1) * $this->per_page == 0)? '1':($this->page-1) * $this->per_page?>-<?php echo (($this->listing_number)<29)?$this->listing_number:($this->page * $this->per_page)?> / <b><?php echo number_format($this->listing_number)?> Ads</b>, Page <?php echo number_format($this->page)?> / <?php echo number_format(ceil($this->listing_number/$this->per_page))?>-->
			<?php echo $this->t('__1__-__2__ /__3__ __4__ Ads__5__, Page __6__ / __7__', null, ((($this->page-1) * $this->per_page == 0)? '1':($this->page-1) * $this->per_page), ((($this->listing_number)<29)?$this->listing_number:($this->page * $this->per_page)), '<b>', number_format($this->listing_number), "</b>", number_format($this->page), number_format(ceil($this->listing_number/$this->per_page)))?>
		</span>
		</h2>
<?php 
//next and prev url settter
$url_product = array();
function pager($cur_page_num, $url_raw, $pages){
	$prev = ($cur_page_num>1)? "&page=".($cur_page_num-1):'';
	$next = ($cur_page_num<$pages)? "&page=".($cur_page_num+1):'';
	
	if(strpos($url_raw, '?')===false)
	{
		//echo "1";
		$url_product['prev'] = $url_product['next'] = $url_raw;
		$url_product['prev'] .= ($cur_page_num>1)? str_replace("&","?",$prev):'';
		$url_product['next'] .= ($cur_page_num<$pages)? str_replace("&","?",$next):'';
	}else
	{
		//if(eregi('&page=[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]', $url_raw))// deprecated..lols
		//echo "2";
		if(preg_match('/page=[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]/i', $url_raw))
		{
			//echo "-2.1";
			$url_product['prev'] = preg_replace("/page=([0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])/", str_replace("&","",$prev), $url_raw);
			$url_product['next'] = preg_replace("/page=([0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])/", str_replace("&","",$next), $url_raw);
		}else
		{
			//echo "-2.2";
			/*if(preg_match('/page=[0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]/i', $url_raw))
			{
				echo "-2.2.1";
				$url_product['prev'] = preg_replace("/page=([0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])/", str_replace("&","",$prev), $url_raw);
				$url_product['next'] = preg_replace("/page=([0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])/", str_replace("&","",$next), $url_raw);
			}else
			{
				echo "-2.2.2";
				$url_product['prev'] = $url_raw.$prev;
				$url_product['next'] = $url_raw.$next;
			}*/
			$url_product['prev'] = $url_raw.$prev;
			$url_product['next'] = $url_raw.$next;
		}
	}
	return $url_product;
}		
		
$pager_url = pager($this->page, $_SERVER["REQUEST_URI"], ceil($this->listing_number/$this->per_page));
$previous_url = $pager_url['prev'];
$next_url = $pager_url['next'];
?>
	    <div class="nav top">
		    <a href="<?php echo $previous_url;?>" class="prev"><span>&lt;</span><?php echo $this->t('PREV')?></a>
		    <form action="<?php echo str_replace(" ","+",$this->company->username);?>" method="get" id="form_sort1">
	            <?php
	            foreach($_GET as $k => $v){
	                if (is_array($v)) {
	                    foreach($v as $k2 => $v2) {
	                        if ($k2 != 'sort') {
	                            ?>
	                            <input type="hidden" name="<?php echo $k.'['.$k2.']'?>" value="<?php echo $v2?>">
	                            <?php
	                        }
	                    }
	                }else {
	                    if ($k != 'sort') {
	                        ?>
	                        <input type="hidden" name="<?php echo $k?>" value="<?php echo $v?>">
	                        <?php
	                    }
	                }
	            }
	            ?>
	
	            <select name="sort" onchange="javascript:if(this.value!='default'){$('#form_sort1').submit();}">
	            	<option value="default"><?php echo $this->t('Sort By...')?></option>
	                <option value="recent" <?php echo !empty($_GET['sort']) && $_GET['sort'] == 'recent' ? 'selected' : ''?>><?php echo $this->t('Most Recent')?></option>
	                <option value="high" <?php echo !empty($_GET['sort']) && $_GET['sort'] == 'high' ? 'selected' : ''?>><?php echo $this->t('Highest Price')?></option>
	                <option value="low" <?php echo !empty($_GET['sort']) && $_GET['sort'] == 'low' ? 'selected' : ''?>><?php echo $this->t('Lowest Price')?></option>
	            </select>
	        </form>
		    <a href="<?php echo $next_url;?>" class="next"><span>&lt;</span><?php echo $this->t('NEXT')?></a>
	    </div>
	    <ul>
	    <?php $i = 0;?>
            <?php foreach($this->list as $listing):?>
            <?php $listing_url = $listing->url[$this->getLanguagePosition()]?>
            	<li>
					<a href="<?php echo $listing_url?>">
						<figure>	
							<img src="<?php echo $this->thumbnail()->scale($listing->photo, 82, 82);?>" alt="<?php echo $this->t('__1__ - photo __2__', null, $listing->title, 1)?>">
						</figure>
						<h1><?php echo $listing->title;//$listing->username?>
						<?php if($listing->sold):?>
                            <?php $tmp_cat = (array)$listing->category_attached; ?>
                            <span class="sold"><?php $tmp = Model_Category::find($tmp_cat[0]); echo $tmp->sold;?></span>
                        <?php endif;?></h1>
						<dl class="location">
                            <?php if(!empty($listing->area_l2)):?>
                                <dd><?php echo Model_Location::find($listing->area_l2)->name?></dd>
                            <?php endif;?>
                        </dl>
						<dl class="date">
							<dd><?php echo date(MEDIUM_DATE_FORMAT, strtotime($listing->posted_at))?></dd>
						</dl>
						<dl class="price">
							<dd>
								<?php if($listing->sold):?>
									<?php echo $this->t('Sold')?>
								<?php else:?>
									<?php if ($i==0):?><dt><span><?php echo $this->t('Price');?></span></dt><?php endif;?>
		                            <?php if (!empty($listing->sale_price) || !empty($listing->rent_price)): ?>
		                                <?php
		                                if (!empty($listing->sale_price)) {
		                                    $sale_price = number_format($listing->sale_price);
		                                    ?><dd>HKD <?php echo $sale_price?> <em> <?php echo $this->t('(Sale)');?></em></dd><?php
		                                }
		                                if (!empty($listing->rent_price)) {
		                                    $rent_price = number_format($listing->rent_price);
		                                    ?><dd>HKD <?php echo $rent_price?> <em> <?php echo $this->t('(Rent)');?></em></dd><?php
		                                }
		                                ?>   
		                                    
		                            <?php elseif (!empty($listing->is_free)):?>
		                                <dd><?php echo $this->t('Free');?></dd>
		                            <?php elseif (!empty($listing->is_contact)):?>
		                                <dd><?php echo $this->t('Please contact');?></dd>
		                            <?php elseif (!empty($listing->price)): ?>
		                                <dd>HKD <?php echo number_format($listing->price);?></dd>
		                            <?php endif;?>
		                        <?php endif;?>
							</dd>
						</dl>
						<span>&gt;</span>
					</a>
				</li>
                <?php $i++;?>
            <?php endforeach;?>
	    </u>
	    <div class="nav bottom">
	    <a href="<?php echo $previous_url;?>" class="prev"><span>&lt;</span><?php echo $this->t('PREV')?></a>
	    <!--p>Page <?php echo number_format($this->page)?> / <?php echo number_format(ceil($this->listing_number/$this->per_page))?></p-->
	    <p><?php echo $this->t('Page __1__ / __2__', null, number_format($this->page), number_format(ceil($this->listing_number/$this->per_page)))?></p>
		<a href="<?php echo $next_url;?>" class="next"><span>&lt;</span><?php echo $this->t('NEXT')?></a>
	    </div>
<?php else:?>
	<h2>
			<span>
			<?php echo $this->t('There are no Ads under __1__ company.', null, $this->company->username);?>
		</span>
		</h2>
<?php endif;?>
	    </section>
<br><br>
	</div>
	
	
    </section>

<!--pre><?php print_r($this->company);?></pre-->

    <?php echo $this->Partial('mobile/other.phtml', 'default'); 
	
	?>
